#include <iostream>
using namespace std;
class Solution {
public:
    void replaceSpace(char* str, int length) {
        if (str == nullptr)return;
        int count = 0;
        int i = 0;
        while (str[i]) {
            if (str[i++] == ' ')count++;
        }
        int end1 = strlen(str);
        int end2 = strlen(str) + count * 2;
        while (end1 >= 0 && end2 >= 0) {
            if (str[end1] == ' ') {
                str[end2--] = '0';
                str[end2--] = '2';
                str[end2--] = '%';
                end1--;
            }
            else {
                str[end2] = str[end1];
                end1--;
                end2--;
            }
        }
    }
};

int main() {
    char arr[1024] = { "We Are Happy" };
    Solution ss;
    ss.replaceSpace(arr, strlen(arr));
    cout << arr << endl;
    return 0;
}